<template>
  <div className="app-container">
    <div className="table-container">
      <base-list
        ref="table"
        url="/jointly_read_activity_apply"
        :options="options"
        :columns="columns"
        :format="format"
        :rules="rules"
        permission="ADMIN"
        @reloadOptions="handleGetOptions"
      />
    </div>
  </div>
</template>

<script>
import {getBaseList, getBaseOptions} from '@/api/common'
import BaseList from '@/components/BaseList/index.vue'

export default {
  name: 'JointlyReadActivityApply',
  components: {BaseList},
  data() {
    return {
      columns: [
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'activity', label: '实际活动', tooltip: '实际活动', type: 'REMOTE_SELECT', remote: {url: '/jointly_read_activity', label: 'name', multiple: false, queryable: true}},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'name', label: '共读标题', tooltip: '共读名称', type: 'WORD'},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'books', label: '共读图书', tooltip: '共读图书', type: 'REMOTE_SELECT_BOOK', remote: {multiple: true}},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'maxUserNum', label: '人数限制', tooltip: '人数限制', type: 'NUMBER', queryable: true, sortable: true},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'expense', label: '报名费', tooltip: '报名费', type: 'NUMBER', queryable: true, sortable: true},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'readStartDate', label: '阅读活动开始日期', tooltip: '阅读活动开始日期', type: 'DATE_TIME', queryable: true, sortable: true},
        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'readEndDate', label: '阅读活动结束日期', tooltip: '阅读活动结束日期', type: 'DATE_TIME', queryable: true, sortable: true},
        {show: false, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'recommend', label: '推荐语', tooltip: '推荐语', type: 'HTML'},

        {show: true, edit: true, notUpdate: true, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'REMOTE_SELECT', remote: {url: '/user_info', label: 'nickName', multiple: false, queryable: true}},

        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'status', label: '审核状态', tooltip: '审核状态', type: 'DICTIONARY', optionKey: 'statusOptions', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'rejectReason', label: '审核未通过原因', tooltip: '审核未通过原因', type: 'WORD'},

        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'auditUser', label: '审核人', tooltip: '审核人', type: 'WORD'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'auditTime', label: '审核时间', tooltip: '审核时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createTime', label: '创建时间', tooltip: '创建时间', type: 'DATE_TIME'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'updateTime', label: '更新时间', tooltip: '更新时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'updateUser', label: '修改人', tooltip: '修改人', type: 'WORD'},
      ],
      format: {
        books: (data, index) => {
          return (data.books || []).map(e => e.name).join(',')
        },
        auditUser: (data, index) => {
          return data.auditUser ? data.auditUser.nickName + '('+data.auditUser.id+')' : ''
        },
        activity: (data, index) => {
          return data.activity ? data.activity.name + '('+data.activity.id+')' : ''
        },
        createUser: (data, index) => {
          return data.createUser ? data.createUser.nickName + '('+data.createUser.id+')' : ''
        },
        updateUser: (data, index) => {
          return data.updateUser ? data.updateUser.nickName + '('+data.updateUser.id+')' : ''
        }
      },
      rules: {
        add: {
          actId: [{required: true, message: '实际活动ID必填!', trigger: 'blur'}],
          name: [{required: true, message: '共读标题必填!', trigger: 'blur'}],
          createUser: [{required: true, message: '创建人必填!', trigger: 'blur'}],
          maxUserNum: [{required: true, message: '人数限制必填!', trigger: 'blur'}],
          readStartDate: [{required: true, message: '阅读活动开始日期必填!', trigger: 'blur'}],
          readEndDate: [{required: true, message: '阅读活动结束日期必填!', trigger: 'blur'}],
          status: [{required: true, message: '审核状态必填!', trigger: 'blur'}],
          books: [{required: true, message: '共读活动申请图书必填!', trigger: 'blur'}],
          recommend: [{required: true, message: '介绍/推荐语必填!', trigger: 'blur'}],

        },
        edit: {
          id: [{required: true, message: '请选择数据!', trigger: 'change'}],
          actId: [{required: true, message: '实际活动ID必填!', trigger: 'blur'}],
          name: [{required: true, message: '共读标题必填!', trigger: 'blur'}],
          createUser: [{required: true, message: '创建人必填!', trigger: 'blur'}],
          maxUserNum: [{required: true, message: '人数限制必填!', trigger: 'blur'}],
          readStartDate: [{required: true, message: '阅读活动开始日期必填!', trigger: 'blur'}],
          readEndDate: [{required: true, message: '阅读活动结束日期必填!', trigger: 'blur'}],
          status: [{required: true, message: '审核状态必填!', trigger: 'blur'}],
          books: [{required: true, message: '共读活动申请图书必填!', trigger: 'blur'}],
          recommend: [{required: true, message: '介绍/推荐语必填!', trigger: 'blur'}],

        }
      },
      options: {
        statusOptions: [
          {id: 'AUDITING', name: '待审核', type: 'warning'},
          {id: 'SUCCESS',name: '通过',type: 'primary'},
          {id: 'REJECT', name: '未通过', type: 'danger'}
        ],
      }
    }
  },

  created() {
    this.handleGetOptions()
  },
  mounted() {
  },
  methods: {
    handleGetOptions() {
      const options = JSON.parse(localStorage.getItem('allOptions'))
      if (options) {
        this.options = Object.assign(this.options, options)
      }
    }
  }
}
</script>


